using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Web.UI.HtmlControls;
using System.Reflection;
using System.Collections;

namespace NewLibrary
{
    public class SimpleEvent : Control, INamingContainer
    {

        public int Value
        {
            get
            {
                this.EnsureChildControls();
                return Int32.Parse(((TextBox)Controls[1]).Text);
            }
            set
            {
                this.EnsureChildControls();
                ((TextBox)Controls[1]).Text = value.ToString();
            }
        }

        protected override void CreateChildControls()
        {

            // Add Literal Control

            this.Controls.Add(new LiteralControl("<h3>" + "Value: "));

            // Add Textbox

            TextBox box = new TextBox();
            box.Text = "0";
            this.Controls.Add(box);

            // Add Literal Control

            this.Controls.Add(new LiteralControl("</h3>"));

            // Add "Add" Button

            LinkButton addButton = new LinkButton();
            addButton.Text = "Add";
            addButton.Click += new EventHandler(this.AddBtn_Click);
            this.Controls.Add(addButton);

            // Add Literal Control

            this.Controls.Add(new LiteralControl(" | "));

            // Add "Subtract" Button

            LinkButton subtractButton = new LinkButton();
            subtractButton.Text = "Subtract";
            subtractButton.Click += new EventHandler(this.SubtractBtn_Click);
            this.Controls.Add(subtractButton);

        }

        private void AddBtn_Click(Object sender, EventArgs e)
        {
            this.Value++;
        }

        private void SubtractBtn_Click(Object sender, EventArgs e)
        {
            this.Value--;
        }
    }
}
